package marmalius;

public class Herblore {

    public int xprate = 1;

    public void unfpot(int playerId, int useditem, int usewith) {
        client c = (client) PlayerHandler.getInstance().getPlayer(playerId);
        int ingredient = 0;

        if (useditem == 227) {
            ingredient = usewith;
        }
        if (usewith == 227) {
            ingredient = useditem;
        }
        if (usewith == 227 && useditem == 227) {}
        if (getunfID(ingredient) != 0) {
            if (c.playerLevel[15] >= lvlreq(ingredient)) { 
                c.deleteItem(227, c.GetItemSlot(227), 1);
                c.deleteItem(ingredient, c.GetItemSlot(ingredient), 1);
                c.addItem(getunfID(ingredient), 1);
                c.addSkillXP(xprate * getxp(ingredient), 15);
                c.startAnimation(3283);
                c.sendMessage(
                        "You add the " + c.GetItemName(ingredient) + " to the "
                        + c.GetItemName(227) + ".");
            } else {
                c.sendMessage(
                        "You need a herblore level of " + lvlreq(ingredient)
                        + " to add the " + c.GetItemName(ingredient)
                        + " to the " + c.GetItemName(227) + ".");
            }
        } else {}
    }

    public int lvlreq(int ingredient) {
        int lvl = 0;

        switch (ingredient) {
        case 249: // guam leave
            lvl = 1;
            break;

        case 251: // marenthil
            lvl = 5;
            break;

        case 253: // tarromin
            lvl = 12;
            break;

        case 255: // harralander
            lvl = 22;
            break;

        case 257: // ranarr
            lvl = 30;
            break;

        case 259: // irit
            lvl = 45;
            break;

        case 261: // avantoe
            lvl = 50;
            break;

        case 263: // kwuarm
            lvl = 55;
            break;

        case 265: // cadantine
            lvl = 66;
            break;

        case 267: // dwarf weed
            lvl = 72;
            break;

        case 269: // torstol
            lvl = 78;
            break;

        case 2481: // lantadyme
            lvl = 76;
            break;

        case 2998: // toadflax
            lvl = 34;
            break;

        case 3000: // snapdragon
            lvl = 63;
            break;

        default:
            lvl = 0;
            break;
        }
        return lvl;
    }

    public int getxp(int ingredient) {
        int xp = 0;

        switch (ingredient) {
        case 249: // guam leave
            xp = 70;
            break;

        case 251: // marenthil
            xp = 90;
            break;

        case 253: // tarromin
            xp = 110;
            break;

        case 255: // harralander
            xp = 130;
            break;

        case 257: // ranarr
            xp = 150;
            break;

        case 259: // irit
            xp = 160;
            break;

        case 261: // avantoe
            xp = 200;
            break;

        case 263: // kwuarm
            xp = 250;
            break;

        case 265: // cadantine
            xp = 320;
            break;

        case 267: // dwarf weed
            xp = 380;
            break;

        case 269: // torstol
            xp = 500;
            break;

        case 2481: // lantadyme
            xp = 650;
            break;

        case 2998: // toadflax
            xp = 760;
            break;

        case 3000: // snapdragon
            xp = 900;
            break;

        default:
            xp = 0;
            break;
        }
        return xp;
    }

    public int getunfID(int ingredient) {
        int unfID = -1;

        switch (ingredient) {
        case 249: // guam leave
            unfID = 91;
            break;

        case 251: // marenthil
            unfID = 93;
            break;

        case 253: // tarromin
            unfID = 95;
            break;

        case 255: // harralander
            unfID = 97;
            break;

        case 257: // ranarr
            unfID = 99;
            break;

        case 259: // irit
            unfID = 101;
            break;

        case 261: // avantoe
            unfID = 103;
            break;

        case 263: // kwuarm
            unfID = 105;
            break;

        case 265: // cadantine
            unfID = 107;
            break;

        case 267: // dwarf weed
            unfID = 109;
            break;

        case 269: // torstol
            unfID = 111;
            break;

        case 2481: // lantadyme
            unfID = 2483;
            break;

        case 2998: // toadflax
            unfID = 3002;
            break;

        case 3000: // snapdragon
            unfID = 3004;
            break;

        default:
            unfID = 0;
            break;
        }
        return unfID;
    }

    public int getpot(int unfpot, int ing) {
        int pot = 0;

        switch (unfpot) {
        case 91:
            if (ing == 221) {
                pot = 121;
            }
            break;

        case 93:
            if (ing == 235 || ing == 237) {
                pot = 175;
            }
            break;

        case 95:
            if (ing == 225) {
                pot = 115;
            }
            break;

        case 97:
            if (ing == 1975 || ing == 1973) {
                pot = 3010;
            }
            break;

        case 99:
            if (ing == 231) {
                pot = 139;
            }
            if (ing == 239) {
                pot = 133;
            }
            break;

        case 101:
            if (ing == 221) {
                pot = 145;
            }
            if (ing == 235 || ing == 237) {
                pot = 181;
            }
            break;

        case 103:
            if (ing == 231) {
                pot = 151;
            }
            if (ing == 2970) {
                pot = 3018;
            }
            break;

        case 105:
            if (ing == 225) {
                pot = 157;
            }
            if (ing == 241 || ing == 243) {
                pot = 187;
            }
            break;

        case 107:
            if (ing == 239) {
                pot = 163;
            }
            break;

        case 109:
            if (ing == 245) {
                pot = 169;
            }
            break;

        case 111:
            if (ing == 247) {
                pot = 189;
            }
            break;

        case 2483:
            if (ing == 241 || ing == 243) {
                pot = 2454;
            }
            if (ing == 3138) {
                pot = 3042;
            }
            break;

        case 3002:
            if (ing == 2150 || ing == 2152) {
                pot = 3034;
            }
            if (ing == 6049) {
                pot = 5954;
            }
            if (ing == 6693) {
                pot = 6687;
            }
            break;

        case 3004:
            if (ing == 223) {
                pot = 3026;
            }
            break;

        default:
            pot = 0;
            break;
        }
        return pot;
    }

    public int getlvlreq(int unfpot, int ing) {
        int lvl = 0;

        switch (unfpot) {
        case 91:
            if (ing == 221) {
                lvl = 1;
            }
            break;

        case 93:
            if (ing == 235 || ing == 237) {
                lvl = 5;
            }
            break;

        case 95:
            if (ing == 225) {
                lvl = 12;
            }
            break;

        case 97:
            if (ing == 1975 || ing == 1973) {
                lvl = 26;
            }
            break;

        case 99:
            if (ing == 231) {
                lvl = 38;
            }
            if (ing == 239) {
                lvl = 30;
            }
            break;

        case 101:
            if (ing == 221) {
                lvl = 45;
            }
            if (ing == 235 || ing == 237) {
                lvl = 48;
            }
            break;

        case 103:
            if (ing == 231) {
                lvl = 50;
            }
            if (ing == 2970) {
                lvl = 52;
            }
            break;

        case 105:
            if (ing == 225) {
                lvl = 55;
            }
            if (ing == 241 || ing == 243) {
                lvl = 60;
            }
            break;

        case 107:
            if (ing == 239) {
                lvl = 66;
            }
            break;

        case 109:
            if (ing == 245) {
                lvl = 72;
            }
            break;

        case 111:
            if (ing == 247) {
                lvl = 78;
            }
            break;

        case 2483:
            if (ing == 241 || ing == 243) {
                lvl = 69;
            }
            if (ing == 3138) {
                lvl = 76;
            }
            break;

        case 3002:
            if (ing == 2150 || ing == 2152) {
                lvl = 34;
            }
            if (ing == 6049) {
                lvl = 68;
            }
            if (ing == 6693) {
                lvl = 81;
            }
            break;

        case 3004:
            if (ing == 223) {
                lvl = 63;
            }
            break;

        default:
            lvl = 0;
            break;
        } 
        return lvl;
    }

    public int getxp(int unfpot, int ing) {
        int xp = 0;

        switch (unfpot) {
        case 91:
            if (ing == 221) {
                xp = 50;
            }
            break;

        case 93:
            if (ing == 235 || ing == 237) {
                xp = 60;
            }
            break;

        case 95:
            if (ing == 225) {
                xp = 70;
            }
            break;

        case 97:
            if (ing == 1975 || ing == 1973) {
                xp = 80;
            }
            break;

        case 99:
            if (ing == 231) {
                xp = 90;
            }
            if (ing == 239) {
                xp = 90;
            }
            break;

        case 101:
            if (ing == 221) {
                xp = 100;
            }
            if (ing == 235 || ing == 237) {
                xp = 100;
            }
            break;

        case 103:
            if (ing == 231) {
                xp = 110;
            }
            if (ing == 2970) {
                xp = 110;
            }
            break;

        case 105:
            if (ing == 225) {
                xp = 120;
            }
            if (ing == 241 || ing == 243) {
                xp = 120;
            }
            break;

        case 107:
            if (ing == 239) {
                xp = 130;
            }
            break;

        case 109:
            if (ing == 245) {
                xp = 130;
            }
            break;

        case 111:
            if (ing == 247) {
                xp = 140;
            }
            break;

        case 2483:
            if (ing == 241 || ing == 243) {
                xp = 150;
            }
            if (ing == 3138) {
                xp = 150;
            }
            break;

        case 3002:
            if (ing == 2150 || ing == 2152) {
                xp = 160;
            }
            if (ing == 6049) {
                xp = 160;
            }
            if (ing == 6693) {
                xp = 160;
            }
            break;

        case 3004:
            if (ing == 223) {
                xp = 170;
            }
            break;

        default:
            xp = 0;
            break;
        } 
        return xp;
    }

    public int unfpots[] = {
        91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 2483, 3002, 3004};
    public boolean isunfpot(int itemID) {
        for (int i = 0; i < unfpots.length; i++) {
            if (unfpots[i] == itemID) {
                return true;
            }
        } 
        return false;
    }
    public int ingredients[] = {
        221, 223, 225, 231, 235, 237, 239, 241, 243, 245, 247, 1973, 1975, 2152,
        2970, 6049, 3138, 6051, 6693, 6018};
    public boolean isingredient(int itemID) {
        for (int i = 0; i < ingredients.length; i++) {
            if (ingredients[i] == itemID) {
                return true;
            }
        }
        return false;
    }

    public void finishpot(int playerId, int useditem, int usewith) {
        int ingredient = 0;
        int unfpot = 0;
       // boolean herbloreaccepted = true;
        client c = (client) PlayerHandler.getInstance().getPlayer(playerId);

        if (isunfpot(useditem) && isingredient(usewith)) {
            ingredient = usewith;
            unfpot = useditem;
        }
        if (isunfpot(usewith) && isingredient(useditem)) {
            ingredient = useditem;
            unfpot = usewith;
        }
        if (isunfpot(usewith) && isunfpot(useditem)) {
            //herbloreaccepted = false;
        }
        if (getpot(unfpot, ingredient) > 0 && getlvlreq(unfpot, ingredient) > 0) {
            if (c.playerLevel[15] >= getlvlreq(unfpot, ingredient)) {
                c.deleteItem(unfpot, c.GetItemSlot(unfpot), 1);
                c.deleteItem(ingredient, c.GetItemSlot(ingredient), 1);
                c.addItem(getpot(unfpot, ingredient), 1);
                c.addSkillXP(xprate * getxp(unfpot, ingredient), 15);
                c.startAnimation(3283);
                c.sendMessage(
                        "You mix the " + c.GetItemName(ingredient)
                        + " into the potion.");
                c.sendMessage(
                        "and succesfully finish Your "
                                + c.GetItemName(getpot(unfpot, ingredient))
                                + ".");
            } else {
                c.sendMessage(
                        "You need a herblore level of "
                                + getlvlreq(unfpot, ingredient) + " to make a "
                                + c.GetItemName(getpot(unfpot, ingredient))
                                + ".");
            }
        } else {
            c.sendMessage(
                    "STOP!, experimenting with potions is dangerous bussiness mate.");
        }
    }

    public int isherb[] = {
        199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 2485, 3049, 3051};
    public boolean isherb(int herbid) {
        for (int i = 0; i < isherb.length; i++) {
            if (isherb[i] == herbid) {
                return true;
            }
        }
        return false;
    }

    public int identify(int herbid) {
        int i = 0;

        switch (herbid) {
        case 199:
            i = 249;
            break;

        case 201:
            i = 251;
            break;

        case 203:
            i = 253;
            break;

        case 205:
            i = 255;
            break;

        case 207:
            i = 257;
            break;

        case 209:
            i = 259;
            break;

        case 211:
            i = 261;
            break;

        case 213:
            i = 263;
            break;

        case 215:
            i = 265;
            break;

        case 217:
            i = 267;
            break;

        case 219:
            i = 269;
            break;

        case 2485:
            i = 2481;
            break;

        case 3049:
            i = 2998;
            break;

        case 3051:
            i = 3000;
            break;
        }
        return i;
    }

    public void IDherb(int playerId, int herbid, int slot) {
        client c = (client) PlayerHandler.getInstance().getPlayer(playerId);

        if (isherb(herbid)) {
            if (c.playerLevel[15] >= lvlreq(identify(herbid))) {
                c.sendMessage(
                        "You took a closer look at the herb and found out it was a "
                                + c.GetItemName(identify(herbid)) + ".");
                c.deleteItem(herbid, slot, 1);
                c.addItem(identify(herbid), 1);
                c.addSkillXP(2 * xprate, 15);
            } else {
                c.sendMessage(
                        "You need a herblore level of "
                                + lvlreq(identify(herbid))
                                + " to identify this herb.");
            }
        } else {}
    }

}
